<?php

namespace App\Console\Commands;

use App\Console\Base;
use App\Models\HallMenuSub;
use common\enum\CommonEnum;

class ActivitySwitch extends Base
{
    /**
     * 控制台命令 signature 的名称。
     *
     * @var string
     */
    protected $signature = self::PREFIX . 'activityswitch {--hall_id=}';


    /**
     * 控制台命令说明。
     *
     * @var string
     */
    protected $description = 'ActivitySwitch';

    /**
     * 执行控制台命令。
     *
     * @return mixed
     */
    public function handle()
    {
        $updateData       = [];
        $hallID       = $this->option('hall_id');
        $activityData = HallMenuSub::select(['id', 'start_time', 'end_time'])->where(['hall_id' => $hallID])->get()->toArray();
        foreach ($activityData as $value) {
            $where = ['id' => $value['id']];
            if (!empty($value['end_time']) && !empty($value['start_time'])) {
                $endTime   = strtotime($value['end_time']);
                $startTime = strtotime($value['start_time']);
                if ($startTime < time() && time() < $endTime) {
                    $updateData['status'] = CommonEnum::ENABLED;
                } else {
                    $updateData['status'] = CommonEnum::DISABLE;
                }
                HallMenuSub::where($where)->update($updateData);
            }
        }
    }
}
